package com.alice.router.guigu;

/**
 * @author alice
 * @date 2021/9/22
 * @apiNote
 */
public class Ticket {
    private int number;

    public synchronized void incr() throws InterruptedException {
        while (number != 0) {
            this.wait();
        }
        number++;
        System.out.println(Thread.currentThread().getName() + " :: " + number);
        this.notifyAll();
    }

    public synchronized void dec() throws InterruptedException {
        while (number != 1) {
            this.wait();
        }
        number--;
        System.out.println(Thread.currentThread().getName() + " :: " + number);
        this.notifyAll();
    }
}
